package com.lz.ovuola.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.lz.ovuola.entity.VersionDo;
import com.lz.ovuola.repository.mysql.impl.VersionRepository;
import com.lz.ovuola.service.VersionService;
import com.lz.ovuola.util.annotation.TargetDataSource;
import com.lz.ovuola.util.constant.DataSourceConsts;
import com.lz.ovuola.util.exception.BusinessException;
import com.lz.ovuola.util.exception.msg.VersionMsgEnum;
import com.lz.ovuola.util.response.ResponseDataPackageUtils;

/**
 * 
 * @author a
 *
 */
@Service("versionService")
public class VersionServiceImpl implements VersionService {

	@Autowired
	private VersionRepository versionRepository;

	/**
	 * 获取版本
	 */

	@TargetDataSource(DataSourceConsts.SECONDARY_DS)
	@Transactional(transactionManager = "transactionManagerDynamic", propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, readOnly = true)
	@Override
	public String getVersion() {
		List<VersionDo> resList = versionRepository.findAll();
		// 不存在版本信息
		if (resList.size() == 0) {
			throw new BusinessException(
					VersionMsgEnum.VERSION_IS_WRONG.getState(),
					VersionMsgEnum.VERSION_IS_WRONG.getMsg());
		}
		return ResponseDataPackageUtils.success(resList.get(0));
	}
}
